/**
 * 
 */
package com.googlecode.agiletools.dailystandup.action;

import java.util.Calendar;
import java.util.Date;

import com.googlecode.agiletools.codereview.ReviewRecordException;
import com.googlecode.agiletools.dailystandup.DailyStandup;
import com.googlecode.agiletools.dailystandup.DailyStandupManager;
import com.opensymphony.xwork2.Action;

/**
 * @author Administrator
 * 
 */
public class DailyStandupAction {

    private int id;

    private DailyStandup dailyStandup = new DailyStandup();

    private DailyStandupManager dailyStandupManager;

    public String create() {
	return Action.INPUT;
    }

    public String detail() {
	dailyStandup = dailyStandupManager.get(id);
	return Action.SUCCESS;
    }

    /**
     * @return the dailyStandup
     */
    public DailyStandup getDailyStandup() {
	return dailyStandup;
    }

    /**
     * @return the id
     */
    public int getId() {
	return id;
    }

    public Date getToday() {
	return Calendar.getInstance().getTime();
    }

    public String modify() {
	dailyStandup = dailyStandupManager.get(id);
	return Action.INPUT;
    }

    public String remove() {
	dailyStandup = dailyStandupManager.get(id);
	dailyStandupManager.delete(id);
	System.out.println("ID = " + dailyStandup.getDate());
	return Action.SUCCESS;
    }

    public String save() {
	try {
	    boolean isNew = dailyStandup.getId() == 0;
	    dailyStandup = dailyStandupManager.save(dailyStandup);
	    if (isNew) {
		Date date = dailyStandup.getDate();
		dailyStandup = new DailyStandup();
		dailyStandup.setDate(date);
		return Action.INPUT;
	    } else {
		return Action.SUCCESS;
	    }
	} catch (ReviewRecordException e) {
	    return Action.ERROR;
	}

    }

    /**
     * @param dailyStandup
     *            the dailyStandup to set
     */
    public void setDailyStandup(DailyStandup dailyStandup) {
	this.dailyStandup = dailyStandup;
    }

    /**
     * @param dailyStandupManager
     *            the dailyStandupManager to set
     */
    public void setDailyStandupManager(DailyStandupManager dailyStandupManager) {
	this.dailyStandupManager = dailyStandupManager;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(int id) {
	this.id = id;
    }

}
